package com.example.jni;

/**
 * Created by x1c on 2018/12/10.
 */

public class DeviceJNI {

    public static int BUFFER_SIZE = 360;
    public  byte[] mWriteBuffer;
    public  byte[] mApplyBuffer;
    public  byte[] mReadBuffer;

    public native  void init();
    public native int add(int x , int y );
    public native void destory();

//    public native int uartOpenJni( int lBaudRate , int lDataBits , int lStopBits , int lParityType);
//    public native int uartCloseJni();
//    public native int uartWriteJni(String sendBuffer);
//    public native String uartReadJni(int readlen, int maxidletime , int maxinterval);

    public native int 		devOpen();
    public native int 		devClose();
    public native byte[] 	devRead(int readlen);
    public native int	 	devWrite(byte[] pwritebuffer,int writelen);

    public native int gpioOpen();
    public native int gpioSendcmd(int cmd, int arg);
    public native int gpioClose();

    /*
	 * 	lBaudRate : 9600    115200
	 *  lDataBits : 数据位       一般8位， 填8
	 *  lStopBits : 一位停止位，分高-低停止位    1：低停止痊       2：高停止位
	 *  lParityType ： 奇偶校验位        0： 无校验位     1：奇 校验   2：偶校验
	 *
	 * */
    public native int uartOpenJni(int uartNum, int lBaudRate, int lDataBits, int lStopBits,int lParityType);

    /*
     *  关闭串口
     * */
    public native int uartCloseJni(int fd);

    /*
     *   mWriteBuffer2  : 写入的buffer
     *   writelen  :   数据长度
     * */
    public native int uartWriteJni(int fd, byte[] mWriteBuffer2, int writelen);

    /*
     *  readleny : 读入的最大长度
     *  maxidletime ： 执行等待的最大时间
     *  maxinterval ： 接收一个数据包，数据间的最大时间，超过这个时间，被分成两个数据包
     * */
    public native byte[] uartReadJni(int fd,int readlen, int maxidletime,int maxinterval);


    public DeviceJNI() {
        mWriteBuffer = new byte[BUFFER_SIZE];
        mApplyBuffer = new byte[BUFFER_SIZE];
        mReadBuffer = new byte[BUFFER_SIZE];
    }


    /**
     * @param args
//     */
//    public static void main(String[] args) {
//        // TODO Auto-generated method stub
//        TestJNI sample = new TestJNI();
//        sample.init();
//    }

    static{
        System.loadLibrary("devicejni");
    }
}
